package com.qiangzhi.context;

/**
 * BaseContext用于存放和取出当前登录的用户id
 */
public class BaseContext {

    /**
     * ThreadLocal为每个线程提供单独一份存储空间
     * 具有线程隔离的效果 只有在线程内才能获取到对应的值 线程外则不能访问当前线程对应的值
     */
    public static ThreadLocal<Long> threadLocal = new ThreadLocal<>();

    public static void setCurrentId(Long id) {
        threadLocal.set(id);
    }

    public static Long getCurrentId() {
        return threadLocal.get();
    }

    public static void removeCurrentId() {
        threadLocal.remove();
    }

}
